package com.framework.modules.dataview.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.Query;
import com.framework.modules.dataview.dao.ViewUserInfoLiveDao;
import com.framework.modules.dataview.entity.ViewUserInfoLiveEntity;
import com.framework.modules.dataview.service.ViewUserInfoLiveService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;


@Service("ViewUserInfoLiveService")
public class ViewUserInfoLiveServiceImpl extends ServiceImpl<ViewUserInfoLiveDao, ViewUserInfoLiveEntity> implements ViewUserInfoLiveService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper<ViewUserInfoLiveEntity> entityEntityWrapper= new EntityWrapper<ViewUserInfoLiveEntity>();
        String[] columns={"rank","pop_count","online_count","state"};
        if(params.containsKey("query")){
            entityEntityWrapper.like("nickname",params.get("query").toString()).or().eq("uid",params.get("query"));
        }
        Page<ViewUserInfoLiveEntity> page = this.selectPage(
                new Query<ViewUserInfoLiveEntity>(params).getPage(),
                entityEntityWrapper.orderDesc(Arrays.asList(columns))
        );

        return new PageUtils(page);
    }

    @Override
    public ViewUserInfoLiveEntity getViewUserInfoLive(Long uid) {
        return this.baseMapper.selectById(uid);
    }

}
